import { Message } from 'element-ui';
import { apis } from '../../../config/request.config.js';
import { request } from '../../common/request.js';
// import accounting from 'accounting'
import { formatMoney, GetDateDiff, deepClone } from '../../common/utils.js';
import Manage from '../Component/AccountsManage/page.vue'
// const infos = [
//   {
//     time: '2019-06-15 18:31:00',
//     type: '账单生成',
//     detail: '25000',
//     moneyType: 1,// 1 冻结，2 支付
//     timeStr: '昨天',
//   }
// ];
// const item = {
//     enterPriseName: '滴滴（重庆）有限公司',
//     lastTask: '6月7号上传3500人',
//     availBalance: '2023132.12',
//     freezeBalance: '2341234.21',
//     settleBalance: '23342.12',
//     totalNum: 102,
//     settleNum: 90,
//     costBalance: '3443.12',
//     isSettle: '是'
// };
const details = [
  {
    name: '张三',
    phone: '185421123',
    idCard: '342342199504013422',
    openAccount: '622123124123',
    actualAmount: '1214123.12',
    settleTime: '20190625 00:19:20',
    tax: '284.23',
    insurance: '123.23',
    totalAmount: '1231421.32'
  },
  {
    name: '李四',
    phone: '185421123',
    idCard: '342342199504013422',
    openAccount: '622123124123',
    actualAmount: '1214123.12',
    settleTime: '20190625 00:19:20',
    tax: '284.23',
    insurance: '123.23',
    totalAmount: '1231421.32'
  }
];
// const supplierList = [1, 2, 3, 4, 5];
export default {
    data() {
      return {
        bills: [],
        labelWidth: '120px',
        sizeModel: 'medium',
        infoList: [],
        infopage: 1,
        param: {
          key: '',
          status: '',
          size: 10,
          page: 1,
        },
        editParam: {
          enterPriseName: '上海ABC广告有限公司',
          status: true,
          settleAmount: 100,
          settleBalance: formatMoney(1231434.12)
        },
        detailParam: {
          size: 50,
          page: 1,
          supplier_id:'',
          task_id: ''
        },
        detailList: [],
        isShowDetail: false,
        supplierList: [],
        supplierId: '',
        taskId: '',
        detailTotal: 0,
        total: 20,
        isShowTaskDetail: false,
        activeNames: ['1'],
      }
    },

    components: {
      Manage
    },

    computed: {

    },
    filters: {
        filterMoney(val) {
            return formatMoney(val);
        }
    },
    methods: {
        getInfoList() {
          this.infoList = Array(3).fill(infos[this.infopage - 1]);
          let now = new Date();
          this.infoList = this.infoList.map((item, index) => {
            let listItem = deepClone(item);
            listItem.timeStr = ['刚刚', '7小时前', '前天'][index];
            listItem.detail = `${listItem.moneyType == 1 ? '冻结' : '支付'}${formatMoney(listItem.detail)}元`;
            return listItem;
          });

          this.total = 20;
        },
        search() {
        //   this.getInfoList();
          this.loading = true;
        request({
            url: 'getTaskList',
            params: this.param,
            method: 'get'
        }).then(res => {
            if (res) {
                // console.log(res)
                this.bills = res.list;
                this.total = res.pagebar.total;
                this.loading = false;
            }
        });
        },
        searchReset() {
          this.param =  {
            key: '',
            status: '',
            size: 10,
            page: 1,
          }
          this.search();
        },
        async getDetails(info){
            await request({
                url: 'getSupplierList',
                method: 'get'
            }).then(res => {
                if (res) {
                    this.supplierList = res.list;
                    this.detailParam = {
                        page: 1,
                        size: 50,
                        supplier_id: res.list[0].id,
                        task_id: info.id
                    }
                }
            });
            this.searchDetail();
            this.isShowDetail = true;
        },
        investMoney() {
          this.$router.push({
            path: '/investMoney'
          })
        },
        handleSizeChange(val) {
          this.param.size = val;
          this.search();
        },
        pageSearch(val) {
            this.param.page = val;
            this.search()
        },
        searchDetail() {
            request({
                url: 'getTaskDetailList',
                method: 'get',
                params: this.detailParam
            }).then(res => {
                if (res) {
                    this.detailList = res.list
                    this.detailTotal = res.pagebar.total
                }
            });

        //   this.detailList = Array(10).fill(details[this.detail.page - 1]);
        //   this.detailList = this.detailList.map((item, index) => {
        //       let listItem = deepClone(item);
        //       listItem.phone += index;
        //       return listItem;
        //   });

          this.detailTotal = 20;
        },
        pageSearchDetail(val) {
          this.detail.page = val;
          this.searchDetail()
        },
        async handleTabChange(val,e) {
            //FIXEDME 不知道咋拿id
            this.detailParam.supplier_id = parseInt(e.target.getAttribute('id').substr(4)) + 1;
            this.detailParam.page = 1;
            this.detailParam.size = 50;

            this.searchDetail()

        },
        handleSizeChangeDetail(val) {
          this.detailParam.size = val;
          this.searchDetail();
        },
        handlePageChangeDetail(val) {
            this.detailParam.page = val;
            this.searchDetail();
          },
        showTaskDetail() {
          for (let i = 0; i < supplierList.length; i += 2) {
            this.supplierList.push(supplierList.slice(i, i + 2));
          }
          this.isShowTaskDetail = true;
        },
        getSupplierDetail() {

        }
    },
    mounted(){
        this.search();
        if (this.$route.query.isShowTaskDetail) {
          this.showTaskDetail();
        }
    }
}
